<script>

import * as echarts from 'echarts';
export default {
  name: 'VisualizationTwo',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data7', {

      }).then(res =>{
        if(res.data.code === 20041) {
          let data1 = [];
          let data2 = [];
          for (let i = 0; i < res.data.data.length; i++) {
            data1.push(
                res.data.data[i].column2
            );
            data2.push(
                res.data.data[i].column1
            )
          }
          this.init(data1, data2);
        }
      }).catch(error =>{
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data1, data2) {
      var chartDom = document.getElementById('main4');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        color: ['#f0b5b5'],
        title: {
          text: '贵阳历史风力'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          },
          formatter: '{b} : {c}天'
        },
        legend: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value',
          boundaryGap: [0, 0.01]
        },
        yAxis: {
          type: 'category',
          data: data1,
        },
        series: [
          {
            type: 'bar',
            data: data2,
            itemStyle: {
              normal: {
                barBorderRadius:[100, 100, 100, 100]
              }
            }
          }
        ]
      };

      option && myChart.setOption(option);

    }
  }

}
</script>

<template>
  <div id="main4"></div>
</template>

<style scoped>
#main4 {
  width: 100%;
  height: 100%;
}
</style>